package com.tg.message.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tg.data.bean.DeviceItem;

import java.util.ArrayList;
import com.tg.message.R;

public class MessageSelectAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<DeviceItem> list;
    public MessageSelectAdapter(Context context, ArrayList<DeviceItem> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.msg_select_pop_item, null);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }

        holder.item = convertView.findViewById(R.id.item_text);
        holder.item.setText(list.get(position).name);
        return convertView;
    }
    public final class ViewHolder {
        public TextView item;
    }
}
